package cvo.chess.tests;

import java.util.List;

import junit.framework.Assert;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import cvo.chess.client.entities.chessboard.ChessboardCoordinate;
import cvo.chess.client.entities.chessboard.Tile;
import cvo.chess.client.entities.game.IChessboard;

public class ChessboardCoordinateTester_4x6 {
	
	//The mock chessboard we will be using in all our test
	IChessboard board;
	
	
	//Set up the mock before every tets. This makes sure that you have every
	//time a clean object.
	//In this particular case, this is redundant.
	//But when using mocking frameworks, you really should do this!
	@Before
	public void setUp() throws Exception {
		
		//We don't actually use the "real" chess board.
		//We won't depend on the real board for those test
		//We simply write an new 'Test Chessboard Anonymous Mock Class Something' to
		//provide the result we want to use in our test. For more advanced mocking
		//you should us mocking frameworks....
		this.board = new IChessboard() {
			
			@Override
			public int getWidth() {
				return 6;
			}
			
			@Override
			public Tile getTileAt(ChessboardCoordinate position) {
				//This function is not required used in those tests
				return null;
			}
			
			@Override
			public int getHeight() {
				return 4;
			}
			
			@Override
			public List<Tile> getAllTiles() {
				//This function is not required used in those tests
				return null;
			}
		};
	}

	@After
	public void tearDown() throws Exception {
		this.board = null;
	}

	@Test
	public void testA1() {
		ChessboardCoordinate bc = new ChessboardCoordinate(board, "A1");
		TestGetters(bc, "A1",0, 3, 18);
	}


	@Test
	public void testA8() {
		ChessboardCoordinate bc = new ChessboardCoordinate(board, "A4");
		TestGetters(bc, "A4", 0, 0, 0);
	}
	
	@Test
	public void testH1() {
		ChessboardCoordinate bc = new ChessboardCoordinate(board, "F4");
		TestGetters(bc, "F4", 5, 0, 5);
	}
	
	@Test
	public void testH8() {
		ChessboardCoordinate bc = new ChessboardCoordinate(board, "F1");
		TestGetters(bc, "F1", 5, 3, 23 );
	}
	

	
	
	private void TestGetters(ChessboardCoordinate bc, String A1notation, int col, int row, int position ){
		
		Assert.assertEquals("ChessboardCoordinate.getA1Notation()", A1notation, bc.getA1Notation()) ;
		Assert.assertEquals("ChessboardCoordinate.getCol()",col, bc.getCol());
		Assert.assertEquals("ChessboardCoordinate.getRow()", row, bc.getRow());
		Assert.assertEquals("ChessboardCoordinate.getPosition()", position , bc.getNummericPosition());
	}
}
